def qsort(arr, left, right):
    if left >= right:
        return arr
    m = arr[left]
    i = left
    j = right
    while i != j:
        while arr[j] >= m and i < j:
            j -= 1
        while arr[i] <= m and i < j:
            i += 1
        if i < j:
           arr[i], arr[j] = arr[j], arr[i]

    arr[left] = arr[i]
    arr[i] = m
    qsort(arr, left, i-1)
    qsort(arr, i+1, right)
    return arr

if __name__ == '__main__':
    arr = [1, 3, 2, 6, 5, -1, 7]
    qsort(arr, 0, len(arr)-1)
    print(arr)
